package com.example.comment_oa.util;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.read.builder.ExcelReaderBuilder;
import com.alibaba.excel.read.builder.ExcelReaderSheetBuilder;
import com.alibaba.excel.write.builder.ExcelWriterBuilder;
import com.alibaba.excel.write.builder.ExcelWriterSheetBuilder;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import java.util.List;
import java.util.Map;

public class EaxyUtils {
    public static String write(String path, List list){
        String path2="D:\\"+path+".xlsx";
        //工作铺对象
        ExcelWriterBuilder write = EasyExcel.write(path2, list.get(0).getClass());
        //工作表对象
        ExcelWriterSheetBuilder sheet = write.sheet();
        //准备数据
        System.out.println("写");
        sheet.doWrite(list);
        return path2;
    }

    public static void read(String path,Object o, BaseMapper baseMapper){
//        ExcelReader reader = ExcelUtil.getReader("D:/study/用户表.xlsx");
//        List<SysUser> sysUsers = reader.read(1,1,SysUser.class);
        ExcelReaderBuilder read = EasyExcel.read(path, o.getClass(), new AccountListener(baseMapper));
        ExcelReaderSheetBuilder sheet = read.sheet();//默认读取第一个
        //读取表中内容
        sheet.doRead();
    }
}
